home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
UTIL_SRC
/
C016.ZIP
/
CALC
/
SELFDOC.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
6KB
|
130 lines
/* Self documentation feature by J. R. Applegate - CSM Computing Center */
#include <stdio.h>
#include <conio.h>
selfdoc()
{
printf("NAME\n");
printf("hoc - Higher order calculator\n\n");
printf("USAGE\n");
printf("hoc [-]\n\n");
printf("DESCRIPTION\n");
printf("Hoc is an enhanced version of the hoc3 calculator described\n");
printf("in Kernighan and Pike's 'The UNIX Programming Environment.'\n");
printf("It supports infix notation with parentheses and variables\n");
printf("and features a rich collection of mathematical operations,\n");
printf("built-in constants and functions. Hoc is easy to use and\n");
printf("examination of the EXAMPLE section below will be sufficient\n");
printf("documentation for many users. The option, -, provides a\n");
printf("brief online help file. Hoc is exited by typing control Z.\n\n");
printf("Numbers are floating point with a friendly display format.\n");
printf("The input format is that recognized by scanf(3): digits,\n");
printf("decimal point, digits, e or E, signed exponent. At least\n");
printf("one digit or a decimal point must be present; the other com-\n");
printf("ponents are optional.\n\n");
more();
printf("Variable names are formed from a letter followed by a string\n");
printf("of letters and digits. The special variable, #, stores the\n");
printf("last number printed. Hoc has the following operators, in\n");
printf("decreasing order of precedence:\n");
printf("^ exponentiation (FORTRAN **), right associative\n");
printf("+ - (unary) plus and minus\n");
printf("* / % multiplication, division, modulo\n");
printf("+ - addition, subtraction\n");
printf("= assignment, right associative\n\n");
printf("The following standard mathematical functions are built-in:\n");
printf("abs(x), acos(x), asin(x), atan(x), atan2(x,y), ceil(x),\n");
printf("cos(x), cosh(x), exp(x), floor(x), gamma(x), hypot(x,y),\n");
printf("int(x), j0(x), j1(x), jn(n,x), log(x), log10(x), pow(x,y),\n");
printf("rand(), sin(x), sinh(x), sqrt(x), srand(x), tan(x), tanh(x),\n");
printf("y0(x), y1(x), yn(n,x).\n\n");
printf("Hoc has the following built-in constants:\n");
printf("DEG 57.29577951308232087680 180/pi, degrees per radian\n");
printf("E 2.71828182845904523536 base of natural logarithms\n");
printf("GAMMA 0.57721566490153286060 Euler-Mascheroni constant\n");
printf("PHI 1.61803398874989484820 (sqrt(5) + 1)/2, golden ratio\n");
printf("PI 3.14159265358979323846 circular transcendental #\n");
more();
printf("The assignment is parsed by default as a statement rather\n");
printf("than as an expression, so assignments typed interactively do\n");
printf("not print their value. The assignment operator assigns the\n");
printf("value of its right operand to its left operand, and yields\n");
printf("the value, so multiple assignments work. The semicolon is\n");
printf("admitted as an alternate terminator to the standard newline\n");
printf("statement terminator.\n\n");
printf("EXAMPLES\n");
printf("Here's an example session with some explanatory comments\n");
printf("inserted:\n");
printf("% hoc\n");
printf("3 + 4\n");
printf(" 7\n");
printf("3^4\n");
printf(" 81\n");
printf("4*(5 + (5 + 6))\n");
printf(" 64\n");
printf("sin(PI/6)\n");
printf(" .5\n");
printf("17/3\n");
printf(" 5.66666667\n");
printf("#/3 /* Note: # stands for last number printed */ \n");
printf(" .666666667\n");
more();
printf("x = 3\n");
printf("y = 4\n");
printf("z = x^2 + y^2\n");
printf("sqrt(z)\n");
printf(" 5\n");
printf("hypot(3,4) /* sqrt of sum of squares */\n");
printf(" 5\n");
printf("j0(0) /* A Bessel function */\n");
printf(" 1\n");
printf("jn(2,0) /* Another one */\n");
printf(" 0\n");
printf("tmin = 1.3 ; c = 6970 /* Semi-colon is alternate terminator */\n");
printf("c* tmin\n");
printf(" 9061\n");
printf("#/2\n");
printf(" 4530.5\n");
printf("dt = .004\n");
printf("1/(2*dt)\n");
printf(" 125\n");
printf("17 % 3 /* 17 mod 3 */\n");
printf(" 2\n");
printf("PI % 1 /* Think about it! */\n");
printf(" .141592654\n");
more();
printf("PI % 0\n");
printf(" 3.14159265\n");
printf("int(PI)\n");
printf(" 3\n");
printf("^Z\n\n");
printf("AUTHOR\n");
printf("Brian W. Kernighan and Rob Pike designed and wrote hoc in\n");
printf("Chapter 8 of 'The UNIX Programming Environment.' Much of\n");
printf("the above documentation is taken from Chapter 9 and Appendix\n");
printf("B of this book. Several enhancements given as problems in\n");
printf("the text have been implemented here by Jack K. Cohen: accept\n");
printf("unary plus; include the modulus operator (implemented for\n");
printf("floating point as in the definition given by Knuth, in\n");
printf("volume 1 of the 'Art of Programming'); remembers the last\n");
printf("number printed in the pseudo-variable, # ; allows semicolon\n");
printf("as an expression terminator in addition to newline; frowns\n");
printf("on assignments to built-in constants such as PI; and has\n");
printf("many more built-in functions including some with 2 and 0\n");
printf("arguments.\n\n");
printf("BUGS/RESTRICTIONS\n");
printf("Kernighan and Pike's extensions of hoc to include control\n");
printf("flow statements and user-defined functions are not imple-\n");
printf("mented.\n");
}
more()
{
char c;
printf("Hit any key to continue ");
c = getchar();
printf("\n");
}